#pragma once
#define UIThreadID 1
#define WALKABLE 0
#define INQUEUE -1
#define CLOSED -2
#define BLOCKED -3
#include <vector>
#include <list>
#include <map>
#include <queue>
using namespace std;
#include <ALWin.h>
using namespace ALWin;
using namespace D2D1;
#define row 20
#define col 20
struct RowCol :POINT {
	int stepCost = 0;
	int distanceToGoal = INFINITY;
	int finalGrade = stepCost + distanceToGoal;
	void updateStepCost(int stepCost) {
		this->stepCost = stepCost;
		finalGrade = stepCost + distanceToGoal;
	}
	RowCol() { x = y = 0; }
	RowCol(int x, int y) {
		this->x = x;
		this->y = y;
	}

	bool operator!=(RowCol const& b) {
		return x != b.x || y != b.y;
	}

	bool operator==(RowCol const &b) {
		return x == b.x && y == b.y;
	}

	RowCol *cameFrom = NULL;
};

struct RowColGraderSmaller {
	bool operator()(const RowCol *a, const RowCol *b) const {
		return a->finalGrade > b->finalGrade;
	}
};

class Level :
	public ALWin::Widget {
public:
	Level(Window *parentWindow, int id, int width = 80, int height = 40, int x = 0, int y = 0);
	~Level();

	PainterD2D *mPainter;
	LRESULT WndProc(UINT msg, WPARAM wParam, LPARAM lParam);

	int grid[row][col];
	int size;
	void onDraw();

	list<RowCol*> AStarPathFinding(POINTF org, POINTF dest, int gridSize);

	list<RowCol*> path;


	POINTF mPlayer;
	POINTF mTarget;

	void ThreadProc(LPVOID param);
};

